package org.feng.vo;

import cn.hutool.core.bean.BeanUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.feng.entity.CustomDict;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 自定义数据字典实体
 *
 * @author feng
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class CustomDictVo implements Serializable {
    private static final long serialVersionUID = 7961526564347009290L;

    private Long id;
    private Long parentId;
    private String name;
    private String dictKey;
    private String dictVal;
    private Integer weight;
    private String status;
    private String createUser;
    private String createUsername;
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", timezone="GMT+8")
    private LocalDateTime createTime;
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", timezone="GMT+8")
    private LocalDateTime updateTime;

    public static CustomDictVo of(CustomDict customDict) {
        CustomDictVo customDictVo = new CustomDictVo();
        BeanUtil.copyProperties(customDict, customDictVo, "status");
        customDictVo.setStatus(customDict.getStatus().getDesc());
        return customDictVo;
    }

    public static List<CustomDictVo> of(List<CustomDict> customDictList) {
        return customDictList.stream().map(CustomDictVo::of).collect(Collectors.toList());
    }
}
